﻿using System.Web.Mvc;
using System.Web.WebPages;
using MvcApplication1.Models;
using MvcApplication1.Views2.UrlUpdating;

namespace MvcApplication1.Controllers
{
    public class UrlUpdatingController : Controller
    {
        public ActionResult Index()
        {
            return Master.Do(
                this,
                _ => Level1Emiter.First(this),
                _ => Level1Emiter.Second(this)).As(View);
        }

        public ActionResult Level2()
        {
            return ActionResult(
                Level2Emiter.First(this),
                Level2Emiter.Second(this));
        }

        public ActionResult Level3()
        {
            return ActionResult(
                Level3Emiter.First(this),
                Level3Emiter.Second(this));
        }

        private ActionResult ActionResult(HelperResult firstFragment, HelperResult secondFragment)
        {
            if (Util.IsAjax)
                return Json(
                    new[]
                    {
                        new HtmlFragment("_up001", firstFragment),
                        new HtmlFragment("_up002", secondFragment)
                    });
            else
                return Master.Do(
                    this,
                    _ => firstFragment,
                    _ => secondFragment).As(View);
        }
    }
}
